package com.dongqb.service;

import java.time.LocalDateTime;
import javax.swing.DefaultListModel;
import com.dongqb.bean.StockInfo;
import com.dongqb.common.CacheData;
import com.dongqb.common.WebUtil;

/**
 * 定时刷新股票信息
 */
public class LoadStockOnTime extends Thread {

	@Override
	public void run() {
		while (true) {
			try {
				// 获取当前时间
				LocalDateTime now = LocalDateTime.now();

				int hour = now.getHour(); // 小时（0-23）
				int minute = now.getMinute(); // 分钟（0-59）

				if (hour == 9 && minute >= 20) {
					process();
				} else if (hour == 10) {
					process();
				} else if (hour == 11 && minute <= 30) {
					process();
				} else if (hour == 13 || hour == 14) {
					process();
				}
				Thread.sleep(1000 * 10);
			} catch (Exception e) {
			}
		}
	}

	public void process() {
		DefaultListModel<StockInfo> listModel = CacheData.mainWin.listModel;
		if (listModel == null || listModel.isEmpty()) {
			return;
		}
		WebUtil.updateStockInfos(listModel);
		CacheData.mainWin.updateJlistModel();
	}
}
